<!-- 车辆类型管理 - 综合表单页面 -->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage" :cell-class-name="cellClassMethod"
      @selection-change="e => selection = e">
    </ex_super_table_page>
    <ex_super_dialog_form ref="formDialog" v-bind="dialog" @afterSubmitSuccess="editFinish" />
  </div>
</template>
<script>
import superTablePageFunction from '@/mixin/super-table-page-function';
export default {
  title: { _key: 'label_any_manage',i18n: true, type: 'label_tms_vehicle_vehicle_model' },
  mixins: [superTablePageFunction],
  components: {},
  data() {
    return {
      selection: [],
      option: {
        search: {
          model: [
            { label: "label_tms_vehicle_vehicle_name", key: "vehicleTypeName", },
            { label: "label_tms_vehicle_model_status", key: "status", type: 'select', enum: 'IsAvailableStatusEnum', },
          ],
        },
        action: [
          {
            label: { _key: 'label_new_any',i18n: true, type: 'label_tms_vehicle_vehicle_model' }, attrs: { icon: "el-icon-plus" }, click: () => {
              // this.dialogTitle = this.$tt({ _key: 'label_new_any', type: 'label_tms_vehicle_vehicle_model' })
              this['$refs']['formDialog'].showNew({
                title: this.$tt({ _key: 'label_new_any', i18n: true,type: 'label_tms_vehicle_vehicle_model' }),
                data: {},
                onlySetData: true,
              })
            }
          },
        ],
        actionExtra: [
          { label: 'label_start_using', attrs: { type: "success" }, click: () => { this.batchEnableOrDisable('ENABLE') } },
          { label: 'label_stop_using', attrs: { type: "danger" }, click: () => { this.batchEnableOrDisable('DISABLED') } },

          { label: 'label_export', attrs: { type: "primary" }, click: this.exportExcel },
        ],
        table: {
          url: "/tms-api/base/TmsVehicleTypeInfoRpc/selectByPage.json",
          model: [
            { type: 'selection', clickToggle: true, },
            { key: 'vehicleTypeName', label: 'label_tms_vehicle_vehicle_name', 'min-width': 140, 'show-overflow-tooltip': true, },
            { key: 'vehicleType', label: 'label_tms_vehicle_model_type', 'width': 100, formatter: (r, c, v, i) => this.$enumShow(v, "VehicleTypeEnum") },
            { key: 'vehicleSpec', label: 'label_tms_vehicle_model_spec', 'width': 100, formatter: (r, c, v, i) => this.$enumShow(v, "VehicleSpecEnum") },
            { key: 'loadWeight', label: 'label_tms_vehicle_bearing_capacity', 'width': 90, },
            { key: 'volume', label: 'label_tms_vehicle_internal_emptiness', 'width': 90, },
            { key: 'length', label: 'label_tms_vehicle_vehicle_length', 'width': 90, },
            { key: 'width', label: 'label_tms_vehicle_vehicle_width', 'width': 90, },
            { key: 'height', label: 'label_tms_vehicle_vehicle_height', 'width': 90, },
            { key: 'status', label: 'label_tms_vehicle_model_status', 'width': 100, formatter: (r, c, v, i) => this.$enumShow(v, "IsAvailableStatusEnum") },
            { key: 'creator', label: 'label_create_user', 'width': 100, 'show-overflow-tooltip': true, },
            { key: 'gmtCreate', label: 'label_create_time', 'width': 120, formatter: (r, c, v, i) => this.$dateFormat(v) },
            {
              type: 'operate', width: 160, operate: [
                {
                  label: 'label_edit', click: (row) => {
                    // this.dialogTitle = this.$tt({ _key: 'label_edit_any', type: 'label_tms_vehicle_vehicle_model' })
                    this['$refs']['formDialog'].showNew({
                      title: this.$tt({ _key: 'label_edit_any',i18n: true, type: 'label_tms_vehicle_vehicle_model' }),
                      params: { "id": row["id"] }
                    })
                  }
                },
                {
                  label: 'label_start_using', type: "confirm-button",
                  url: '/tms-api/base/TmsVehicleTypeInfoRpc/enableOrDisable.json', message: 'label_sure_to_enable_this',
                  buttonClass: "button_text_success", confirmButtonType: 'success',
                  if: (row) => row.status == 'DISABLED', urlType: 'json',
                  params: (row) => {
                    return { idList: [row["id"]], status: 'ENABLE' }
                  }, done: ['tip', () => this.editFinish()]
                },
                {
                  label: 'label_stop_using', type: "confirm-button",
                  url: '/tms-api/base/TmsVehicleTypeInfoRpc/enableOrDisable.json', message: 'label_sure_to_disable_this',
                  buttonClass: "button_text_danger", confirmButtonType: 'danger',
                  if: (row) => row.status == 'ENABLE', urlType: 'json',
                  params: (row) => {
                    return { idList: [row["id"]], status: 'DISABLED' }
                  }, done: ['tip', () => this.editFinish()]
                },
              ],
            }
          ],

        }
        ,

      },

      dialogTitle: '',
      dialog: {
        customClass: 'dialog_auto',
        submitUrl: '/tms-api/base/TmsVehicleTypeInfoRpc/saveUpdate.json',
        detailUrl: '/tms-api/base/TmsVehicleTypeInfoRpc/detail.json',
        form: {
          itemClass: "form_item_mini", inputClass: "form_input_small",
          formClass: "form_mini_col2",
          inline: true,
          model: [
            { header: "label_base_info", },
            { key: 'vehicleType', label: 'label_tms_vehicle_model_type', type: 'select', enum: 'VehicleTypeEnum' },
            { key: 'vehicleSpec', label: 'label_tms_vehicle_model_spec', type: 'select', enum: 'VehicleSpecEnum' },
            { key: 'loadWeight', label: 'label_tms_vehicle_bearing_capacity_1', append: ' t', appendClass: 'input_slot_div_mini' },
            { key: 'volume', label: 'label_tms_vehicle_internal_emptiness_1', append: 'm³', appendClass: 'input_slot_div_mini' },
            { key: 'length', label: 'label_tms_vehicle_vehicle_length_1', append: ' m', appendClass: 'input_slot_div_mini' },
            { key: 'width', label: 'label_tms_vehicle_vehicle_width_1', append: ' m', appendClass: 'input_slot_div_mini' },
            { key: 'height', label: 'label_tms_vehicle_vehicle_height_1', append: ' m', appendClass: 'input_slot_div_mini' },
            { header: "label_tms_vehicle_overhead_info", },
            {
              key: 'vehiclePropertyList', label: 'label_tms_vehicle_vehicle_type_attr', itemClass: "form_item_small",
              type: 'checkbox-group', enum: 'VehiclePropertyEnum'
            },
            { key: 'vehicleTypeImage', label: 'label_tms_vehicle_car_picture', type: 'upload-img', },

          ],
          rules: {
            'vehicleType': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'vehicleSpec': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'loadWeight': {
              required: true, trigger: 'blur', validator: (r, v, cb) => {
                if (!this.$reg.DigitNumber(v, 3, 9)) {
                  return cb(this.$tt("tip_check_decimal_digit_int", { digit: 3, int: 9 }))
                }
                cb()
              },
            },
            'volume': {
              required: true, trigger: 'blur', validator: (r, v, cb) => {
                if (!this.$reg.DigitNumber(v, 2, 9)) {
                  return cb(this.$tt("tip_check_decimal_digit_int", { digit: 2, int: 9 }))
                }
                cb()
              },
            },
            'length': {
              required: true, trigger: 'blur', validator: (r, v, cb) => {
                if (!this.$reg.DigitNumber(v, 2, 9)) {
                  return cb(this.$tt("tip_check_decimal_digit_int", { digit: 2, int: 9 }))
                }
                cb()
              },
            },
            'width': {
              required: true, trigger: 'blur', validator: (r, v, cb) => {
                if (!this.$reg.DigitNumber(v, 2, 9)) {
                  return cb(this.$tt("tip_check_decimal_digit_int", { digit: 3, int: 9 }))
                }
                cb()
              },
            },
            'height': {
              required: true, trigger: 'blur', validator: (r, v, cb) => {
                if (!this.$reg.DigitNumber(v, 2, 9)) {
                  return cb(this.$tt("tip_check_decimal_digit_int", { digit: 3, int: 9 }))
                }
                cb()
              },
            },
          },
        }
      },
    };
  },
  methods: {
    cellClassMethod({ row, column, rowIndex, columnIndex }) {
      if (column.property == 'status') {
        if (row.status == 'ENABLE') {
          return 'color_success'
        } else if (row.status == 'DISABLED') {
          return 'color_danger'
        }
      }
      return ""
    },
    batchEnableOrDisable(status) {
      if (this.$clickFast()) return
      if (_.isEmpty(this.selection)) {
        return this.$message.error("请勾选车辆类型")
      }
      if (this.selection.some(it => it.status == status)) {
        return this.$message.error("勾选的车辆类型状态不符")
      }
      let isENABLE = status == 'ENABLE'
      this.$confirm(`${isENABLE ? '启用' : '停用'}选中的【${this.selection.length}】个单据, 是否继续?`, this.$tt('label_tip'), {
        type: 'warning'
      }).then(() => {
        this.$ajax({
          url: "/tms-api/base/TmsVehicleTypeInfoRpc/enableOrDisable.json",
          method: 'post', type: 'json',
          loading: this.$tt("tip_submiting"),
          data: { idList: this.selection.map(it => it.id), status },
          success: (res) => {
            this.$message.success(this.$tt("tip_operate_success"))
            this.editFinish()
          }
        })
      }).catch(() => {
      });

    },
    editFinish() {
      this.reload()
      this.$refreshStoreCommonDataGroup('/tms-api/base/TmsVehicleTypeInfoRpc/selectLabel.json')
    },
    exportExcel() {
      this.$downloadFile({
        loading: true,
        type: 'json',
        url: '/tms-api/base/TmsVehicleTypeInfoRpc/exportExcel.json',
        data: {
          vehicleTypeIds: this.selection.map(it => it.id),
          ...this.getSuperTablePage().getSearchFormData()
        },
      })
    },
  }
};

</script>
<style></style>
